using System;
using GammaJul.ReSharper.GammaXaml.ContextActions.Xaml;
using GammaJul.ReSharper.GammaXaml.Highlightings.Xaml;
using JetBrains.Annotations;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Intentions.Extensibility;
using JetBrains.ReSharper.Intentions.Extensibility.Menu;
using JetBrains.ReSharper.Psi.Xaml.Tree;
using JetBrains.Util;

namespace GammaJul.ReSharper.GammaXaml.QuickFixes.Xaml {

	/// <summary>
	/// Quick fix that changes a dependency property registered type.
	/// </summary>
	[QuickFix]
	public sealed class UseXStaticFix : RelativeSourceToXStaticActionBase, IQuickFix {
		private readonly XStaticCanBeUsedHighlighting _highlighting;

		/// <summary>
		/// Gets a cache key referencing an instance of <see cref="UseXStaticFix"/>.
		/// </summary>
		public static readonly Key<UseXStaticFix> InstanceKey = new Key<UseXStaticFix>("UseXStaticFix");

		/// <summary>
		/// Finds the <see cref="IRelativeSourceUsage"/> that this action uses.
		/// </summary>
		/// <returns>A <see cref="IRelativeSourceUsage"/> implementation, or <c>null</c>.</returns>
		protected override IRelativeSourceUsage GetRelativeSource() {
			return _highlighting.RelativeSource;
		}

		public void CreateBulbItems(BulbMenu menu, Severity severity) {
			menu.ArrangeQuickFix(this, severity);
		}

		public bool IsAvailable(IUserDataHolder cache) {
			cache.PutData(InstanceKey, this);
			return true;
		}

		public UseXStaticFix([NotNull] XStaticCanBeUsedHighlighting highlighting) {
			if (highlighting == null)
				throw new ArgumentNullException("highlighting");
			_highlighting = highlighting;
		}
	}

}
